using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Adex
{
    /// <summary>
    /// Controller class for VERSIONS
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class VersionController
    {
        // Preload our schema..
        Version thisSchemaLoad = new Version();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public VersionCollection FetchAll()
        {
            VersionCollection coll = new VersionCollection();
            Query qry = new Query(Version.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public VersionCollection FetchByID(object Id)
        {
            VersionCollection coll = new VersionCollection().Where("ID", Id).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public VersionCollection FetchByQuery(Query qry)
        {
            VersionCollection coll = new VersionCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object Id)
        {
            return (Version.Delete(Id) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object Id)
        {
            return (Version.Destroy(Id) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int UserID,string MediaType,string Brand,string VersionX,int? Duration,string Agency,string Advertiser,long? NoOfInsertions,long? Investment,string Clip,string Image)
	    {
		    Version item = new Version();
		    
            item.UserID = UserID;
            
            item.MediaType = MediaType;
            
            item.Brand = Brand;
            
            item.VersionX = VersionX;
            
            item.Duration = Duration;
            
            item.Agency = Agency;
            
            item.Advertiser = Advertiser;
            
            item.NoOfInsertions = NoOfInsertions;
            
            item.Investment = Investment;
            
            item.Clip = Clip;
            
            item.Image = Image;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(long Id,int UserID,string MediaType,string Brand,string VersionX,int? Duration,string Agency,string Advertiser,long? NoOfInsertions,long? Investment,string Clip,string Image)
	    {
		    Version item = new Version();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.Id = Id;
				
			item.UserID = UserID;
				
			item.MediaType = MediaType;
				
			item.Brand = Brand;
				
			item.VersionX = VersionX;
				
			item.Duration = Duration;
				
			item.Agency = Agency;
				
			item.Advertiser = Advertiser;
				
			item.NoOfInsertions = NoOfInsertions;
				
			item.Investment = Investment;
				
			item.Clip = Clip;
				
			item.Image = Image;
				
	        item.Save(UserName);
	    }
    }
}
